#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

class Solution {
private:
	class new_int{
	public:
		int value;
		bool operator < (new_int &b){
			if(__builtin_popcount(this->value) != __builtin_popcount(b.value)){
				return __builtin_popcount(this->value) < __builtin_popcount(b.value);
			}
			return this->value < b.value;
		}
		new_int(int x){
			this->value = x;
		}
	};
public:
    vector<int> sortByBits(vector<int>& arr) {
		vector<new_int> temp;
		for(int i = 0; i < arr.size(); i++){
			temp.push_back(new_int(arr[i]));
		}
		sort(temp.begin(), temp.end());
		vector<int>ans;
		for(int i = 0; i < temp.size(); i++){
			ans.push_back(temp[i].value);
		}
		return ans;
    }
};

int main(){
	return 0;
}

//2020.11.6
//
